import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-04-06
 * Time: 14:56
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.建立连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("1.95.194.117");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("wangkun");
        connectionFactory.setPassword("200411");
        connectionFactory.setVirtualHost("study");
        Connection connection = connectionFactory.newConnection();

        //2.通信
        Channel channel = connection.createChannel();

        //3.声明队列
        channel.queueDeclare("message.queue",true,false,false,null);


        //4.发送消息
        for (int i = 0; i < 10; i++) {
            String message = "hello message!";
            channel.basicPublish("","message.queue",null,message.getBytes());
        }


        //5.资源释放
        channel.close();
        connection.close();
    }
}
